package cn.ceplc.nlu.base.service.impl;

import cn.ceplc.nlu.base.repository.BaseRepository;
import cn.ceplc.nlu.base.domain.BaseEntity;
import cn.ceplc.nlu.base.service.BaseService;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;
import java.util.Optional;

@Service
public class BaseServiceImpl<T extends BaseEntity<PK>, PK extends Serializable> implements BaseService<T, PK> {

    protected BaseRepository<T, PK> baseRepository;


    @Override
    public T insert(T entity) {
        return baseRepository.save(entity);
    }

    @Override
    public void delete(PK id) {
        baseRepository.deleteById(id);
    }

    @Override
    public T update(T entity) {
        return baseRepository.save(entity);
    }

    @Override
    public List<T> findAll() {
        return baseRepository.findAll();
    }

    @Override
    public Optional<T> findById(PK id) {
        return baseRepository.findById(id);
    }
}
